<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <title>用户后台</title>
    <link rel="stylesheet" href="/layui/css/layui.css">
    <link rel="stylesheet" href="/layui/css/admin.css">
</head>
<body class="layui-layout-body">
<div class="layui-layout layui-layout-admin">
    <div class="layui-header">
        <div class="layui-logo">个人管理</div>
        <!-- 头部区域（可配合layui已有的水平导航） -->

        <ul class="layui-nav layui-layout-right">
            <li class="layui-nav-item">
                <a href="javascript:;">
                    <img src="/layui/images/1.jpg" class="layui-nav-img">
                    <%= user.username %>
                </a>
                <dl class="layui-nav-child">
                    <dd><a href="">基本资料</a></dd>
                    <dd><a href="">安全设置</a></dd>
                </dl>
            </li>
            <li class="layui-nav-item"><a href="/user/<%= user.username %>">回到主页</a></li>
        </ul>
    </div>

    <div class="layui-side layui-bg-black">
        <div class="layui-side-scroll">
            <!-- 左侧导航区域（可配合layui已有的垂直导航） -->
            <ul class="layui-nav layui-nav-tree" lay-filter="test">
                <li class="layui-nav-item layui-nav-itemed">
                    <a class="" href="javascript:;">文章</a>
                    <dl class="layui-nav-child">
                        <dd><a href="/admin/task/addtask">文章发布</a></dd>
                        <dd class="layui-this"><a href="/admin/task/all">文章管理</a></dd>
                    </dl>
                </li>
                <% if(user.level >= 10) { %>
                    <li class="layui-nav-item">
                        <a href="/admin/user">用户管理</a>
                    </li>
                <% } %>
            </ul>
        </div>
    </div>

    <div class="layui-body">
        <!-- 内容主体区域 -->
        <div style="padding: 15px;">
            <fieldset class="layui-elem-field">
                <legend>文章管理</legend>
            </fieldset>

            <table id="demo" lay-filter="demo"></table>
            <script type="text/html" id="barDemo">
                <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除文章</a>
            </script>
        </div>
    </div>

    <div class="layui-footer">
        <!-- 底部固定区域 -->
        公告 - 底部固定区域
    </div>
</div>
<script src="/layui/layui.js"></script>
<script>
    //JavaScript代码区域
    layui.use(['element', 'table', 'form', 'rate', 'laydate', 'layedit', 'layer'], function () {
        var element = layui.element;
        var form = layui.form;
        var layer = layui.layer;
        var layedit = layui.layedit;
        var table = layui.table;
        var $ = layui.$;
        table.render({
            elem: '#demo',
            page: true,//开启分页
            url: '/admin/task/all',
            method: 'post',
            cols: [
                [
                    {field: 'title', title: '标题'},
                    {field: 'dir', title: '所属目录'},
                    {field: 'class', title: '文章类型'},
                    {
                        field: 'time', title: '发布时间', templet: function (d) {
                            return new Date(d.time).toLocaleString()
                        }
                    },
                    {toolbar: '#barDemo'}
                ]
            ]
        })
        table.on('tool(demo)', function (obj) {
            layer.confirm('是否删除?', {icon: 3, title: '提示'}, function (index) {
                $.ajax({
                    url: '/admin/task/del',
                    method: 'post',
                    data: {
                        _id: obj.data._id
                    }
                })
                layer.close(index);
                location.reload();
            })
        })
    })
</script>
</body>
</html>

